package app

import (
	"chatgpt/helper"
	"chatgpt/helper/code"
	"chatgpt/services"
	"github.com/gin-gonic/gin"
)

// 个人的订单列表， 默认选择 下单中的订单
func MineOrderListHandle(ctx *gin.Context) {

}

// 订单详情页面
func OrderShowHandle(ctx *gin.Context) {
	order_no := ctx.Query("OrderNo")
	order := services.OrderSrv.GetOrder(order_no)
	if order == nil {
		helper.Count(ctx, code.ORDER_NO_ERR, nil)
		return
	}
	order.Product = services.ProductSrv.First(order.ProcID)
	helper.Count(ctx, code.SUCCESS, services.OrderSrv.Display(order))
}

// 下单
func OrderFirmHandle(ctx *gin.Context) {
	proc_id := ctx.Query("ProcID") //购买商品ID
	order := services.OrderSrv.FirmOrder(map[string]any{
		"ProcID": proc_id,
		"UUID":   ctx.GetString("UUID"),
	})
	mc := services.OrderSrv.Save(order)
	helper.Count(ctx, mc, map[string]any{
		"Order": order.ConvToMap(),
	})
}
